package tksDB

type TksRank struct {
	RankName string
	Cache    *TksCache
}

func NewRank(rankName string, cache *TksCache) *TksRank {
	return &TksRank{rankName, cache}
}

//add people
func (r *TksRank) New(key string, score float64) {
	r.Cache.Redis.Zadd(r.RankName, []byte(key), score)
}

//add score for people
func (r *TksRank) Add(key string, score float64) {
	r.Cache.Redis.Zincrby(r.RankName, []byte(key), score)
}

func (r *TksRank) GetRange(begin int, end int) map[string]float64 {
	ret := make(map[string]float64)
	//
	ranks, _ := r.Cache.Redis.Zrevrange(r.RankName, begin, end)
	for i := 0; i < len(ranks); i++ {
		s, _ := r.Cache.Redis.Zscore(r.RankName, ranks[i])
		ret[string(ranks[i])] = s
	}
	return ret
}

//get score of people
func (r *TksRank) Get(key string) float64 {
	s, _ := r.Cache.Redis.Zscore(r.RankName, []byte(key))
	return s
}
